<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class checkEmailRegister extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(Request $request)
    {
        return [
            'email' => [
                'bail',
                'required',
                'unique:shop_Member',
                'e-mail',
            ],
            'password' => [
                'bail',
                'required',
                'regex:/^([%$#0-9a-zA-Z.*-^]+)$/',
                'between:[8,16]',
                Rule::in([$request->repassword]),
            ],
            'emailCode' => [
                'bail',
                'required',
                Rule::in([$request->session()->get('code')]),
            ],
        ];
    }

    public function messages()
    {
        return [
            'email.required' => '请输入邮箱',
            'email.unique' => '邮箱已被注册',
            'email.e-mail' => '邮箱格式不正确',
            'password.required' => '请设置密码',
            'password.regex' => '密码格式不正确，只能由数字字母.*-^%$#组成',
            'password.between' => '密码长度在8-16位之间',
            'password.in' => '两次密码不一致',
            'Code.required' => '没有输入验证码',
            'Code.in' => '验证码不正确',
        ];
    }
}
